﻿<AspNetMembershipManager:EditDialogWindow x:Class="AspNetMembershipManager.User.CreateUserWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
		xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
		xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:vm="clr-namespace:AspNetMembershipManager.User"
        xmlns:AspNetMembershipManager="clr-namespace:AspNetMembershipManager"
        FocusManager.FocusedElement="{Binding ElementName=txtUserName}"
		d:DataContext="{d:DesignInstance vm:CreateUserModel}" mc:Ignorable="d"
        Title="Create user" Height="343" Width="563">
    <Window.CommandBindings>
        <CommandBinding Command="Save" CanExecute="Ok_CanExecute" Executed="Ok_Executed" />
    </Window.CommandBindings>
	<Grid>
		<Grid.Resources>
			<BooleanToVisibilityConverter x:Key="BooleanToVisibilityConverter"/>
		</Grid.Resources>
		<Grid.ColumnDefinitions>
			<ColumnDefinition Width="*" />
		</Grid.ColumnDefinitions>
		<Grid.RowDefinitions>
			<RowDefinition Height="auto" />
			<RowDefinition Height="auto" />
			<RowDefinition Height="auto" />
		</Grid.RowDefinitions>
		<GroupBox Header="User details" HorizontalAlignment="Stretch" Margin="12, 12, 12, 0" VerticalAlignment="Top" Grid.Row="0">
            <Grid>
                <Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
				</Grid.RowDefinitions>
				<Label Content="Username:" Grid.Column="0" Grid.Row="0" />
				<Label Content="Password:" Grid.Column="0" Grid.Row="1" />
				<Label Content="Confirm password:" Grid.Column="0" Grid.Row="2" />
				<Label Content="Email address:" Grid.Column="0" Grid.Row="3" />
				<TextBox Name="txtUserName" Grid.Column="1" Grid.Row="0"
                         Validation.Error="Validation_Error"
                         Text="{Binding Username, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
				<PasswordBox Grid.Column="1" Grid.Row="1"
							 Visibility="{Binding IsManualPasswordEntry, Converter={StaticResource BooleanToVisibilityConverter}}"
							 Validation.Error="Validation_Error"
							 vm:PasswordBoxAssistant.BindPassword="true"
							 vm:PasswordBoxAssistant.BoundPassword="{Binding Path=Password, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
							  />
				<PasswordBox Grid.Column="1" Grid.Row="2"
							 IsEnabled="{Binding IsManualPasswordEntry}"
							 Validation.Error="Validation_Error"
							 vm:PasswordBoxAssistant.BindPassword="true"
							 vm:PasswordBoxAssistant.BoundPassword="{Binding Path=PasswordConfirmation, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged, ValidatesOnDataErrors=true, NotifyOnValidationError=true}"
							  />
				<TextBox Text="{Binding Password, Mode=OneWay}" IsReadOnly="True" Grid.Column="1" Grid.Row="1" Visibility="{Binding IsPasswordAutoGenerated, Converter={StaticResource BooleanToVisibilityConverter}}" />
				<TextBox Grid.Column="1" Grid.Row="3" Validation.Error="Validation_Error" Text="{Binding EmailAddress}" />
            </Grid>
        </GroupBox>
		<GroupBox Header="Password question and answer" IsEnabled="{Binding RequiresQuestionAndAnswer}" Margin="12, 12, 12, 0" HorizontalAlignment="Stretch" VerticalAlignment="Top" Grid.Row="1">
			<Grid>
				<Grid.ColumnDefinitions>
					<ColumnDefinition Width="Auto" />
					<ColumnDefinition Width="*" />
				</Grid.ColumnDefinitions>
				<Grid.RowDefinitions>
					<RowDefinition Height="auto" />
					<RowDefinition Height="auto" />
				</Grid.RowDefinitions>
				<Label Content="Password question:" Grid.Column="0" Grid.Row="0" />
				<Label Content="Password answer:" Grid.Column="0" Grid.Row="1" />
				<TextBox Grid.Column="1" Grid.Row="0" Validation.Error="Validation_Error" Text="{Binding PasswordQuestion, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
				<TextBox Grid.Column="1" Grid.Row="1" Validation.Error="Validation_Error" Text="{Binding PasswordQuestionAnswer, ValidatesOnDataErrors=true, NotifyOnValidationError=true}" />
			</Grid>
		</GroupBox>
		<Grid Grid.Row="2">
			<Grid.ColumnDefinitions>
				<ColumnDefinition Width="Auto" />
				<ColumnDefinition Width="*" />
			</Grid.ColumnDefinitions>
			<Grid.RowDefinitions>
				<RowDefinition Height="auto" />
				<RowDefinition Height="auto" />
			</Grid.RowDefinitions>
			<Label Style="{StaticResource ErrorMessage}" Height="31" Grid.Row="0" Grid.ColumnSpan="2">
				<TextBlock Text="{Binding Error}" TextWrapping="Wrap" />
			</Label>
			<StackPanel Orientation="Horizontal" Grid.Row="1" Grid.Column="0">
				<StackPanel.Resources>
					<Style TargetType="{x:Type Button}">
						<Setter Property="Margin" Value="10,0,10,0" />
						<Setter Property="Padding" Value="10,0,10,0" />
					</Style>
				</StackPanel.Resources>
				<Button Content="Autogenerate password" Click="AutoGeneratePassword_Click" />
			</StackPanel>
			<StackPanel Orientation="Horizontal" Grid.Row="1" FlowDirection="RightToLeft" Grid.Column="1">
				<StackPanel.Resources>
					<Style TargetType="{x:Type Button}">
						<Setter Property="Margin" Value="10,0,0,0"/>
					</Style>
				</StackPanel.Resources>
				<Button Content="Save" IsDefault="True" Width="75" Command="Save" />
				<Button Content="Cancel" IsCancel="True" Width="75" />
			</StackPanel>
		</Grid>	</Grid>
</AspNetMembershipManager:EditDialogWindow>
